/*******************************************************************************
  * Copyright(c) 2023 Levetop Semiconductor Co.,Led. All rights reserved.
  * @file     data.h
  * @author   UartTFT Application Team
  * @version  V0.0.1
  * @date     2023-01-01
  * @brief    
 ********************************************************************************/

#ifndef _DATA_H
#define _DATA_H

#include <stdint.h>
#include "delay.h"
#include "module_select.h"

// tft info
extern uint32_t gBaudrate;
extern uint16_t LCD_XSIZE_TFT; // screen resolution
extern uint16_t LCD_YSIZE_TFT;
extern uint16_t LCD_VBPD;
extern uint16_t LCD_VFPD;
extern uint16_t LCD_VSPW;
extern uint16_t LCD_HBPD;
extern uint16_t LCD_HFPD;
extern uint16_t LCD_HSPW;
extern uint8_t gPCLKRISING;
extern uint8_t gHSYNCPolarity;
extern uint8_t gVSYNCPolarity;
extern uint8_t gDEPolarity;
// extern uint8_t R_ANGLE;
extern uint32_t TFT_color;

// pic
#define DMA_LEN1 1024
#define DMA_LEN2 2048
#define DMA_LEN3 3072
#define DMA_LEN4 4096
extern uint8_t DMA_rxbuf1[];	//for dma buffer
extern uint8_t DMA_rxbuf2[];
extern uint8_t DMA_txbuf1[2048];
extern uint8_t Table_color[512];
#define MAX_PixelSize 153600
extern uint8_t m_PngData[MAX_PixelSize];
//extern uint8_t MODE1_BUFF[12*14*2];
//extern uint8_t MODE2_BUFF[12*14*2];
//extern uint8_t MODE3_BUFF[12*14*2];
//extern uint8_t MODE4_BUFF[12*14*2];
//extern uint8_t MODE1_icon_BUFF[30*99*2];	
//extern uint8_t MODE2_icon_BUFF[30*99*2];
//extern uint8_t MODE3_icon_BUFF[30*99*2];
//extern uint8_t MODE4_icon_BUFF[30*99*2];


//extern uint8_t MODE1_BUFF[];
//extern uint8_t MODE2_BUFF[];
//extern uint8_t MODE3_BUFF[];
//extern uint8_t MODE4_BUFF[];
//extern uint8_t MODE1_icon_BUFF[];
//extern uint8_t MODE2_icon_BUFF[];
//extern uint8_t MODE3_icon_BUFF[];
//extern uint8_t MODE4_icon_BUFF[];

extern uint16_t *p16_m_PngData;
extern uint16_t *p16_DMA_rxbuf1;
extern uint16_t *p16_DMA_rxbuf2;

extern uint32_t FullScreen_addr, FullScreen_color;	//for full-screen info
extern uint8_t FullScreen_flag;

extern uint16_t Page_VirW, Page_VirH;		// page resolution
extern uint32_t Page_VirAddr, Page_VirLen;
extern uint8_t Page_VirFlag;

// zip picture
typedef struct
{
	uint16_t w;
	uint16_t h;
	uint8_t depth; // Picture color depth
	uint8_t Cflag; // Picture type
	//	uint8_t  Table_color[512];
} zippic_struct;
extern zippic_struct zippic;

typedef struct
{
	uint16_t x;
	uint16_t y;
	uint16_t w;
	uint16_t h;
	uint32_t addr;
	uint32_t len; // picture size
	uint8_t flag; // picture type, 0x10:pure color
	uint8_t mix;  // mix mode, 0:with fullscreen interface   1:with specific pictures

} _PICINFO;
extern _PICINFO PICINFO[];
extern uint8_t IconBG_Flag;



//-------------------- backlight ---------------------------------
extern uint16_t gControlDuty;

//---------------Macro used to control USART receiving data-----------------------------
#define RX_SIZE (4096 + 2) //(4096+2)
typedef struct
{
	uint8_t Flag;
	uint8_t Buf[RX_SIZE];
	uint16_t Count;
} USART_RX_INFO;
extern USART_RX_INFO gUsartRx;

//--------------------- TP ----------------------------------
extern uint8_t First_press;
extern uint16_t First_pressX, First_pressY;
extern uint8_t RTP_read_Flag;
extern uint16_t RTP_time;

#define CT_MAX_TOUCH 5 // Number of points supported by capacitive screen
typedef struct
{
	uint8_t (*scan)(void);	  // Scan the touch screen;
	uint8_t sta;			  // Status flag,  0:Not pressed	1:First press	2:Keep pressing
	uint16_t x[CT_MAX_TOUCH]; // Screen coordinates
	uint16_t y[CT_MAX_TOUCH]; // Screen coordinates
	uint16_t px;			  // Physical coordinates
	uint16_t py;			  // Physical coordinates
	uint8_t readspace;		  // Coordinate reading interval

	uint8_t flag; // Read from flash. When the value is 0x5a, it means that there are four parameters in flash
	float xfac;
	float yfac;
	float xoff;
	float yoff;
} TP_INFO;
extern TP_INFO gTpInfo;

typedef union
{
	float xfac;
	int8_t s[4];
} TP_xfac;
typedef union
{
	float xoff;
	int8_t s[4];
} TP_xoff;
typedef union
{
	float yfac;
	int8_t s[4];
} TP_yfac;
typedef union
{
	float yoff;
	int8_t s[4];
} TP_yoff;
extern TP_xfac gTpxfac;
extern TP_xoff gTpxoff;
extern TP_yfac gTpyfac;
extern TP_yoff gTpyoff;

#endif /* _DATA_H */
